package cn.edu.nju.oraldefense.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import cn.edu.nju.oraldefense.dao.DeanDao;
import cn.edu.nju.oraldefense.model.Dean;

@Component("deanDao")
public class DeanDaoImpl implements DeanDao {
	HibernateTemplate hibernateTemplate;

	public static final String USERNAME = "username";

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void save(Dean instance) {
		hibernateTemplate.save(instance);
	}

	public Dean findById(int id) {
		Dean instance = (Dean) getHibernateTemplate().get(
				"cn.edu.nju.oraldefense.model.Dean", id);
		return instance;
	}

	public List findByProperty(String propertyName, Object value) {
		System.out.println("finding Dean instance with property: "
				+ propertyName + ", value: " + value);
		String queryString = "from Dean as model where model." + propertyName
				+ "= ?";
		return hibernateTemplate.find(queryString, value);
	}

	public List findByUsername(String username) {
		return findByProperty(USERNAME, username);
	}

	public void update(Dean instance) {
		hibernateTemplate.update(instance);
	}

	public void delete(Dean instance) {
		hibernateTemplate.delete(instance);
	}
}
